<?php

!defined('SYSTEM_INCLUDED') && exit('Access Denied');

Class BaseModel{
	
	public $dbType;
	
	public $needDb = true;
	
	public $db;
	
	public function __Construct($dbType=''){
		if($this->needDb){
			$dbType = empty($dbType) ? Config::get('DB_TYPE') : $dbType;
			$config = array();
		    $config['dbCharset'] = Config::get('DB_CHARSET');
	    	$config['hostname'] = Config::get('HOST_NAME');
	    	$config['hostport'] = Config::get('HOST_PORT');
	    	$config['username'] = Config::get('DB_USERNAME');
	    	$config['password'] = Config::get('DB_PASSWORD');
	    	$config['database'] = Config::get('DB_DBNAME');
	    	SysBase::import("System.Db.{$dbType}");
	    	$this->db = SysBase::getInstance($dbType,$config);
		    if(!$this->db){
		    	throw new CommonException ("Db init falilure!");
	    	}
		    $this->db->connect($config);
		}
	}
	
}